
<template>
  <div>
    <el-dialog
        title="添加学生"
        :visible.sync="dialogVisible"
        width="30%"
    >
  <span> <el-form ref="form" :model="form" label-width="80px">
    <el-form-item label="姓名">
      <el-input v-model="form.name"></el-input>
    </el-form-item>
            <el-form-item label="学号">
      <el-input v-model="form.account"></el-input>
    </el-form-item>
    <el-form-item label="性别">
      <el-input v-model="form.gender"></el-input>
    </el-form-item>

        <el-form-item label="民族">
      <el-input v-model="form.nation"></el-input>
    </el-form-item>
        <el-form-item label="密码">
      <el-input v-model="form.password"></el-input>
    </el-form-item>
        <el-form-item label="生源地">
      <el-input v-model="form.birthplace"></el-input>
    </el-form-item>
  </el-form></span>
      <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="submit">确 定</el-button>
  </span>
    </el-dialog>
  </div>
</template>
<script>
import {_addStudent} from '../../../../api/super_admin'

export default {
  name: 'StudentAddDialog',
  data () {
    return {
      dialogVisible: false,
      form: {
        name: '',
        gender: '',
        nation: '',
        account: '',
        password: '',
        birthplace: '',
        classId: 1,
        major: 1,
        isDeleted: 0
      }
    }
  },
  methods: {
    show () {
      this.dialogVisible = true
    },
    submit () {
      for (let item in this.form) {
        if (item === '') {
          this.$message({
            message: '所有字段非空',
            type: 'error'
          })
          return
        }
      }
      this.$confirm('确定添加学生？', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        _addStudent(this.form).then(res => {
          if (res.status) {
            this.$message({
              message: '添加成功',
              type: 'success'
            })
            this.$emit('ok')
            this.dialogVisible = false
          } else {
            this.$message({
              message: '添加失败',
              type: 'warning'
            })
          }
        })
      }).catch()
    }
  }
}
</script>

<style scoped>

</style>
